import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * @since 2019-12-20
 */
import request from 'utils/request';
import { CPAAS_IAM, VERSION_IS_OP } from 'utils/config';
import { getCurrentOrganizationId } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
/**
 * 清理缺失权限记录
 * @async
 * @function clearPermissionRecordInterface
 * @param {object} params - 参数对象
 */

export function clearPermissionRecordInterface(_x) {
  return _clearPermissionRecordInterface.apply(this, arguments);
}
/**
 * 批量添加权限集
 * @async
 * @function refreshPermissionInterface
 * @param {object} params - 参数对象
 */

function _clearPermissionRecordInterface() {
  _clearPermissionRecordInterface = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var checkType, clearType, url;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            checkType = params.checkType, clearType = params.clearType;
            url = VERSION_IS_OP ? "".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/permission-check/clear?checkType=").concat(checkType, "&clearType=").concat(clearType) : "".concat(CPAAS_IAM, "/v1/permission-check/clear?checkType=").concat(checkType, "&clearType=").concat(clearType);
            return _context.abrupt("return", request(url, {
              method: 'DELETE'
            }));

          case 3:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _clearPermissionRecordInterface.apply(this, arguments);
}

export function patchAddPermissionInterface(_x2) {
  return _patchAddPermissionInterface.apply(this, arguments);
}
/**
 * 刷新权限集合
 * @async
 * @function refreshPermissionSet
 * @param {object} params - 参数对象
 */

function _patchAddPermissionInterface() {
  _patchAddPermissionInterface = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var url;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            url = VERSION_IS_OP ? "".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/permission-check/not-pass-api/batch-assign") : "".concat(CPAAS_IAM, "/v1/permission-check/not-pass-api/batch-assign");
            return _context2.abrupt("return", request(url, {
              body: params,
              method: 'POST'
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _patchAddPermissionInterface.apply(this, arguments);
}

export function refreshPermissionSet(_x3) {
  return _refreshPermissionSet.apply(this, arguments);
}
/**
 * 刷新权限集合
 * @async
 * @function refreshPermissionSet
 * @param {object} params - 参数对象
 */

function _refreshPermissionSet() {
  _refreshPermissionSet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    var url;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            url = VERSION_IS_OP ? "".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/permission-check/mismatch-api/batch-refresh") : "".concat(CPAAS_IAM, "/v1/permission-check/mismatch-api/batch-refresh");
            return _context3.abrupt("return", request(url, {
              body: params,
              method: 'POST'
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _refreshPermissionSet.apply(this, arguments);
}

export function refreshMenuPermissionSet(_x4) {
  return _refreshMenuPermissionSet.apply(this, arguments);
}

function _refreshMenuPermissionSet() {
  _refreshMenuPermissionSet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var url;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            url = VERSION_IS_OP ? "".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/permission-check/menu-permission-api/batch-assign") : "".concat(CPAAS_IAM, "/v1/permission-check/menu-permission-api/batch-assign");
            return _context4.abrupt("return", request(url, {
              body: params,
              method: 'POST'
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _refreshMenuPermissionSet.apply(this, arguments);
}